<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['item']=$this->pdo_get('merch',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
$return['merchs']=$this->pdo_getall('merch',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
$return['plugin_icon']=$return['item']['logo'];
$this->session('plugin_icon',$return['item']['logo']);
$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
$return['item']['logo']=$return['item']['logo']?$return['item']['logo']:$avatar;
$return['item']['endtime']=$return['item']['endtime']?date('Y-m-d',$return['item']['endtime']):'';
$gameall=$this->pdo_getall('game',array('merchid'=>$merchid),'id','id');
$access['gamesnum']=count($gameall);
if($gameall){
	$game_ids=array_keys($gameall);
}else{
	$game_ids=array(0);
}
$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
$access['member_day']=$this->pdo_count('member',array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid'],'createtime >'=>$daytime),'id');
$access['member_all']=$this->pdo_count('member',array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid']),'id');
$access['sao_day']=$this->pdo_count('sao_log',array('uniacid'=>$_SESSION['uniacid'],'game_id'=>$game_ids,'createtime >'=>$daytime),'id');
$access['sao_all']=$this->pdo_count('sao_log',array('uniacid'=>$_SESSION['uniacid'],'game_id'=>$game_ids),'id');
$access['coupon_day']=$this->pdo_count('coupon_log',array('uniacid'=>$_SESSION['uniacid'],'game_id'=>$game_ids,'createtime >'=>$daytime),'id');
$access['coupon_all']=$this->pdo_count('coupon_log',array('uniacid'=>$_SESSION['uniacid'],'game_id'=>$game_ids),'id');
$access['merch_all']=$this->pdo_count('merch',array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid']),'id');
//视频数据
$videodata['avg_play_duration']=$this->pdo_getsum('video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'avg_play_duration');
$videodata['total_comment']=$this->pdo_getsum('video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'total_comment');
$videodata['total_like']=$this->pdo_getsum('video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'total_like');
$videodata['total_play']=$this->pdo_getsum('video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'total_play');
$videodata['total_share']=$this->pdo_getsum('video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'total_share');
$return['access']=$access;
$return['videodata']=$videodata;
$return['clearfee0']=price($clearfee0);
$return['commission_money0']=price($commission_money0);
if($_SESSION['os']=='windows'){
	//月份
	for($i=0;$i<12;$i++){
				if($i==0){
					$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
					$yueend = time();
					
				}else{
					$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
					$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
				}
				$params=array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid']);
				$params['createtime between']=array($yuestart,$yueend);
				$month12[$i] = date('Y-m',strtotime('-'.$i.' month'));
				//$monthaccess[]=pdo_count('core_access_log',$params);
				$accessline[$i]=$this->pdo_count('member',$params);
				//$monthcredit2[]=pdo_getsum('core_members',$params,'credit2');
	}
	$accessline=array_reverse($accessline);
	$month12=array_reverse($month12);
	$htmls=array(
				array('type'=>'data','tpltype'=>4,'one_num'=>4,'title'=>'今日/总数据指标','datas'=>array(
					array('title'=>'今日/总扫码数','num'=>2,'data'=>array($access['sao_day'],$access['sao_all']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'今日/总用户数','bgcolor'=>'#009933','num'=>2,'data'=>array($access['member_day'],$access['member_all']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'今日/总优惠券','bgcolor'=>'#3366FF','num'=>2,'data'=>array($access['coupon_day'],$access['coupon_all']),'datatitle'=>array('昨日','比前日')),
					array('title'=>'今日/总视频数','bgcolor'=>'#FF3300','num'=>2,'data'=>array($access['member_day'],$access['member_all']),'datatitle'=>array('客户数','申请数')),
				)),
				array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'月度用户数据','datas'=>array(
					'datas'=>array(
						array('name'=>'用户数','value'=>$accessline),
					),
					'xdatas'=>$month12,
				)),
	);	
	$return['htmls']=$htmls;
}
set_html('title','商户后台');
exi($return);